﻿using Azure.Core;
using B.S.BasicData.Api.Write.Application.Command.GridPerson;
using B.S.BasicData.Api.Write.Filters;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Write.Controllers
{
    /// <summary>
    /// 网格人员控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController] 
    public class GridPersonController : ControllerBase
    {
        private readonly IMediator mediator;

        /// <summary>
        /// 在构造函数里注入中介者组件
        /// </summary>
        /// <param name="mediator">mediator中介者组件</param>
        public GridPersonController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 新增网格人员接口
        /// </summary>
        /// <param name="request">网格人员表单(请求命令)</param>
        /// <returns>响应包装类</returns>
        [HttpPost]
        [Filters.AccessTokenFilter]
        public Task<ApiResult<int>> CreateGridPerson(CreateGridPersonCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除网格人员
        /// </summary>
        /// <param name="request">要删除的网格人员id</param>
        /// <returns>响应包装类</returns>
        [HttpPut]
        [AccessTokenFilter]
        public Task<ApiResult<int>> DelGridPerson(DelGridPersonCommand request)
        {
            return mediator.Send(request);
        }


        /// <summary>
        /// 更新网格人员
        /// </summary>
        /// <param name="request">要更新网格人员的表单</param>
        /// <returns>响应包装类</returns>
        [HttpPut]
        [AccessTokenFilter]
        public Task<ApiResult<int>> UpdateGridPerson(UpdateGridPersonCommand request)
        {
            return mediator.Send(request);
        }
    }

} 

